<!--
Copyright 2010 Gerschel A. Payne
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
-->
<body bgcolor="#CC9999">
<div style="background-color:#FF9933; border-style:ridge; border-color:#993300; border-width:10px">
<p align="center"><a href="../panel.php">Back to Main Panel</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="setup.php?create=0">Main Setup</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="setup.php?create=1">Create htaccess and htpasswd</a><br /><br /><a href="http://www.dreamhost.com/donate.cgi?id=13171"><img border="0" alt="Donate towards my web hosting bill!" src="https://secure.newdream.net/donate3.gif" /></a></p>
<?php
include 'config.php';
if (isset($_POST["Submit"])) {

$string = '<?php 
$key = "'. $_POST["key"]. '";
$domain = "'. $_POST["domain"]. '";
$dbname = "'. $_POST["dbname"]. '";
?>';

$fp = fopen("config.php", "w");
fwrite($fp, $string);
fclose($fp);

?>
<p style="color:white">config.php File Rewritten</p>
<?php
}
if ($_GET['create']=="0"){
?>
<form action="" method="post" name="install" id="install">
  <p>
    <input name="key" type="text" id="key" value="<?php echo "$key"?>"> 
    API Key
</p>
  <p>
    <input name="domain" type="text" id="domain" value="<?php echo "$domain" ?>"> 
    Domain
</p>
  <p>
    <input name="dbname" type="text" id="dbname" value="<?php echo "$dbname" ?>">
  DB Name </p>
  <p>
    <input type="submit" name="Submit" value="Setup">
  </p>
</form>
<?php
}
if ($_GET["create"]=="1"){

?>
<form action="" method="post" name="htaccess" id="htaccess">
	<p>
    <input name="username" type="text" id="username"/>
    Username
    </p>
    <p>
    <input name="password" type="text" id="password"/>
    Password
    </p>
    <input type="submit" name="sub_htaccess" value="Create .htaccess and .htpasswd" />
</form>
<?php
}
if (isset($_POST["sub_htaccess"])){
$pathtohtpasswd = dirname(__FILE__);
$htaccessstring = "AuthType Basic
AuthName \"My Protected Area\"
AuthUserFile $pathtohtpasswd/.htpasswd
Require valid-user";

$fp = fopen("../.htaccess", "w");
fwrite($fp, $htaccessstring);
fclose($fp);

$username = $_POST["username"];
$clearPassword = $_POST["password"];
$cryptpassword = crypt($clearPassword, base64_encode($clearPassword));

$htpasswdstring = "$username".":"."$cryptpassword";
$htp = fopen(".htpasswd","w");
fwrite($htp, $htpasswdstring);
fclose($htp);
?>
<p style="color:white">Files (Re)Written: htaccess & htpasswd</p>
<?php
}
?>
<p align="center">Copyright Gerschel Payne<br />Please leave feedback on <a href="http://groups.google.com/group/dreamhost-api-php-webpanel/topics">dreamhost-api-php-webpanel google group</a><br />
View Apache 2.0 License <a href="http://www.apache.org/licenses/LICENSE-2.0">Here</a></p>
</div>
</body>